package com.data.modules.online.cgform.converter.p009a;

import java.util.List;
import java.util.Map;

import com.data.common.system.api.ISysBaseAPI;
import com.data.common.system.vo.DictModel;
import com.data.common.util.SpringContextUtils;
import com.data.common.util.ConvertUtils;
import com.data.modules.online.cgform.util.CgformUtil;
import com.data.modules.online.cgform.converter.FieldCommentConverter;
import com.data.modules.online.cgreport.util.CgReportSqlUtil;

public class ConfigConvert implements FieldCommentConverter {

    protected ISysBaseAPI f117a;

    protected String f118b;

    protected String f119c;

    protected String f120d;

    protected String f121e;

    public ConfigConvert() {
        this.f117a = (ISysBaseAPI) SpringContextUtils.getBean(ISysBaseAPI.class);
    }

    public ConfigConvert(String str, String str2, String str3) {
        this();
        this.f119c = str;
        this.f120d = str2;
        this.f121e = str3;
    }

    public String getField() {
        return this.f118b;
    }

    public void setField(String field) {
        this.f118b = field;
    }

    public String getTable() {
        return this.f119c;
    }

    public void setTable(String table) {
        this.f119c = table;
    }

    public String getCode() {
        return this.f120d;
    }

    public void setCode(String code) {
        this.f120d = code;
    }

    public String getText() {
        return this.f121e;
    }

    public void setText(String text) {
        this.f121e = text;
    }

    @Override
    public String converterToVal(String txt) {
        String str;
        if (ConvertUtils.isNotEmpty(txt)) {
            String str2 = this.f121e + "= '" + txt + CgformUtil.f229C;
            int indexOf = this.f119c.indexOf("where");
            if (indexOf > 0) {
                str = this.f119c.substring(0, indexOf).trim();
                str2 = str2 + CgReportSqlUtil.f391b + this.f119c.substring(indexOf + 5);
            } else {
                str = this.f119c;
            }
            List queryFilterTableDictInfo = this.f117a.queryFilterTableDictInfo(str, this.f121e, this.f120d, str2);
            if (queryFilterTableDictInfo != null && queryFilterTableDictInfo.size() > 0) {
                return ((DictModel) queryFilterTableDictInfo.get(0)).getValue();
            }
        }
        return null;
    }

    @Override
    public String converterToTxt(String val) {
        String str;
        if (ConvertUtils.isNotEmpty(val)) {
            String str2 = this.f120d + "= '" + val + CgformUtil.f229C;
            int indexOf = this.f119c.indexOf("where");
            if (indexOf > 0) {
                str = this.f119c.substring(0, indexOf).trim();
                str2 = str2 + CgReportSqlUtil.f391b + this.f119c.substring(indexOf + 5);
            } else {
                str = this.f119c;
            }
            List queryFilterTableDictInfo = this.f117a.queryFilterTableDictInfo(str, this.f121e, this.f120d, str2);
            if (queryFilterTableDictInfo != null && queryFilterTableDictInfo.size() > 0) {
                return ((DictModel) queryFilterTableDictInfo.get(0)).getText();
            }
        }
        return null;
    }

    @Override
    public Map<String, String> getConfig() {
        return null;
    }
}
